home *** CD-ROM | disk | FTP | other *** search
/ PC-X 1997 October / pcx14_9710.iso / swag / pointers.swg / 0031_Displaying Pointer Values on Screen.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-05-26  |  949 b   |  35 lines

  1. { Convert it to 2 words and then do it. You can do it like this; }
  2. Type
  3.  St4  = string[4];
  4.  PRec = record
  5.   Ofs, Seg: Word;
  6.  end;
  7.  
  8. Var
  9.  P:Pointer;
  10.  P2:PRec absolute P;
  11.  
  12. Function Hexw(w:word):st4;
  13. var s:st4; c:byte; n:array [1..2] of byte absolute w;
  14. begin
  15.  s:='';
  16.  for c:=2 downto 1 do s:=s+hexid[n[c] shr 4]+hexid[n[c] and $f];
  17.  hexw:=s;
  18. end;
  19.  
  20. Begin
  21.  Writeln('Pointer P is at address: ',P2.Seg,':',P2.Ofs,'.');
  22.  writeln('In hex, that''s ',hexw(p2.seg),':',hexw(p2.ofs,'.');
  23. End.
  24. {
  25. You can also use typecasting instead of absolute variables. To do this,
  26. you would use PRec(p) instead of P2 in all places.
  27.  
  28. > am making an exitprocedure for runtime errors, but when I try to write
  29. > the address, its not allowed. I triedto convert it to a word but no-go.
  30. > Anyone, any ideas would be nicely taken.
  31.  
  32. It's not 1 word but 2. Word is 2 bytes, longint and pointer are 4. PRec
  33. splits it into 2 fields each of size Word.
  34. }
  35.